/*
 * Copyright 2012 Marsrutai.lt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.fragment;

import lt.marsrutai.mobile.android.activity.intent.StopsIntentHolder;
import lt.marsrutai.mobile.android.adapter.TrackBookmarkAdapter;
import lt.marsrutai.mobile.android.fragment.task.GetTrackBookmarksTaskFragment;
import lt.marsrutai.mobile.android.fragment.task.TaskFragment;
import lt.marsrutai.mobile.android.model.TrackBookmark;
import lt.marsrutai.mobile.android.task.GetTrackBookmarksTask;
import lt.marsrutai.mobile.android.widget.ListViewAdapter;
import android.view.View;
import android.widget.ListView;

/**
 * Fragment which displays track bookmarks
 * 
 * @author Justas
 */
public class TrackBookmarksFragment extends BookmarksFragment<TrackBookmark> {

    private static final String GET_TRACK_BOOKMARKS_TASK_FRAGMENT = "GetTrackBookmarksTaskFragment";

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        sendTrackData(getBookmarks().get(position));
    }

    @Override
    protected ListViewAdapter<TrackBookmark> createAdapter() {
        return new TrackBookmarkAdapter(getActivity());
    }

    private void sendTrackData(TrackBookmark trackBookmark) {
        StopsIntentHolder intentHolder = new StopsIntentHolder(getActivity());
        intentHolder.setScopeFolder(trackBookmark.getScopeFolder());
        intentHolder.setScopeName(trackBookmark.getScopeName());
        intentHolder.setTransportId(trackBookmark.getTransportId());
        intentHolder.setScheduleId(trackBookmark.getScheduleId());
        intentHolder.setScheduleName(trackBookmark.getScheduleName());
        intentHolder.setScheduleTrackName(trackBookmark.getScheduleTrackName());        
        intentHolder.setTrackId(trackBookmark.getTrackId());
        intentHolder.setTrackName(trackBookmark.getTrackName());
        startActivity(intentHolder.getIntent());
    }

    @Override
    protected String getTaskBroadcastAction() {
        return GetTrackBookmarksTask.BROADCAST_ACTION;
    }

    @Override
    protected Class<? extends TaskFragment<?, ?, ?>> getTaskFragmentClass() {
        return GetTrackBookmarksTaskFragment.class;
    }

    @Override
    protected String getBookmarksTaskFragmentTag() {
        return GET_TRACK_BOOKMARKS_TASK_FRAGMENT;
    }

}
